/**
 * SPDX-FileCopyrightText: 2023-2025 Sangfor Technologies Inc.
 * SPDX-License-Identifier: Mulan PSL v2
 */
/**
 * @file created by zzz 2019/10/26.
 */

import Validator from '../validation/validator';
import SfVueComponent from '@sxf/sf-vue-component';
import {parseIPv4} from 'src/util/format';

let ipv4Validator = SfVueComponent.vtypes.get('ipv4').validator;

export default class IPRange extends Validator {
    verify (v) {
        let [start, end] = v.split('-');
        if (ipv4Validator.verify(start) !== true) {
            return _('起始IP不符合IPv4格式');
        }
        if (ipv4Validator.verify(end) !== true) {
            return _('结束IP不符合IPv4格式');
        }
        let startVal = parseIPv4(start);
            let endVal = parseIPv4(end);
        if (startVal > endVal) {
            return _('起始IP不能超过结束IP');
        }
        return true;
    }
};
